import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/9 10:08
 * @description 画树形图，回溯
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.numTilePossibilities("ABA");
    }
    public int numTilePossibilities(String tiles) {
        int[] cnt = new int[26];
        for (char ch: tiles.toCharArray()) {
            cnt[ch-'A']++;
        }
        return dfs(cnt);
    }
    public int dfs(int[] cnt) {
        int res = 0;
        for (int i = 0; i < 26; i++) {
            if (cnt[i] == 0) {
                continue;
            }
            res++;
            cnt[i]--;
            res += dfs(cnt);
            cnt[i]++;
        }
        return res;
    }
}
